package club.emergency.wechat.dictionary.operate.consumer.service.fallback_factory;

import club.emergency.wechat.common.response.ResponseEntity;
import club.emergency.wechat.common.response.StatusCode;
import club.emergency.wechat.dictionary.operate.consumer.service.DictionaryOperateConsumer;
import club.emergency.wechat.model.dictionary.DictionaryChild;
import club.emergency.wechat.model.dictionary.DictionaryParent;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * Create with IntelliJ IDEA
 * Project Name: wechat
 * Package Name: club.emergency.wechat.dictionary.operate.consumer.service.fallback_factory
 * Date: 2019/3/25
 *
 * @author: 快乐的小菌菌
 * Description:
 */
@Component
public class DictionaryOperateFallbackFactory implements FallbackFactory<DictionaryOperateConsumer> {
    @Override
    public DictionaryOperateConsumer create(Throwable throwable) {
        return new DictionaryOperateConsumer() {
            @Override
            public String saveParent(DictionaryParent dictionaryParent) {
                return ResponseEntity.error(StatusCode.DB_SAVE_ERROR, "新增父字典表数据失败！", throwable.getMessage());
            }

            @Override
            public String modifyParent(DictionaryParent dictionaryParent) {
                return ResponseEntity.error(StatusCode.DB_MODIFY_ERROR, "修改父字典表数据失败！", throwable.getMessage());
            }

            @Override
            public String removeParent(Long id) {
                return ResponseEntity.error(StatusCode.DB_REMOVE_ERROR, "删除父字典表数据失败！", throwable.getMessage());
            }

            @Override
            public String saveChild(DictionaryChild dictionaryChild) {
                return ResponseEntity.error(StatusCode.DB_SAVE_ERROR, "新增子字典表数据失败！", throwable.getMessage());
            }

            @Override
            public String modifyChild(DictionaryChild dictionaryChild, String keyName) {
                return ResponseEntity.error(StatusCode.DB_MODIFY_ERROR, "修改子字典表数据失败！", throwable.getMessage());
            }
        };
    }
}
